package com.doordu.framework.cloud.xxl.enums;

import com.xxl.job.core.handler.impl.GlueJobHandler;
import com.xxl.job.core.handler.impl.MethodJobHandler;
import com.xxl.job.core.handler.impl.ScriptJobHandler;
import org.springframework.util.StringUtils;

/**
 * @author zxw
 * @date 2020/9/24 23:49
 */
public enum HandlerTypeEnums {
    GLUE_HANDLER("glue", GlueJobHandler.class),
    METHOD_HANDLER("method", MethodJobHandler.class),
    SCRIPT_HANDLER("script", ScriptJobHandler.class),
    ;
    private String name;
    private Class cls;

    public static Class choiceJobHandler(String handlerName) {
        if (StringUtils.isEmpty(handlerName)) {
            return MethodJobHandler.class;
        }
        for (HandlerTypeEnums handlerTypeEnums : HandlerTypeEnums.values()) {
            if (handlerTypeEnums.getName().equals(handlerName)) {
                return handlerTypeEnums.getCls();
            }
        }
        return null;
    }

    HandlerTypeEnums(String name, Class cls) {
        this.name = name;
        this.cls = cls;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Class getCls() {
        return cls;
    }

    public void setCls(Class cls) {
        this.cls = cls;
    }
}
